package dao

import (
	"gitee.com/cyanbleeze/go-image-management/internal/model"
	"gitee.com/cyanbleeze/go-image-management/pkg/app"
	"gitee.com/cyanbleeze/go-image-management/pkg/util"
)

func (d *Dao) CreateUser(username string, nickname string, password string) error {
	user := model.User{
		Username: username,
		Nickname: nickname,
		Password: util.EncodeMD5(password),
	}
	return user.Create(d.engine)
}

func (d *Dao) GetValidUser(username string, password string) (*model.User, error) {
	user := model.User{
		Username: username,
		Password: util.EncodeMD5(password),
	}
	return user.CheckByUsernameAndPassword(d.engine)
}

func (d *Dao) GetUser(id uint) (*model.User, error) {
	user := model.User{}
	user.ID = id
	return user.GetByID(d.engine)
}
func (d *Dao) GetUserListInID(ids [][]interface{}, page int, pageSize int) ([]*model.User, error) {
	user := model.User{}
	return user.ListInID(d.engine, ids, app.GetPageOffset(page, pageSize), pageSize)
}
